from django.core import serializers
from django.http import HttpResponse
from sjgapp.models import myuser

def getall(request):
    allresult = myuser.objects.all()[20:30]
    print(allresult)
    data = serializers.serialize('json', allresult)
    return HttpResponse(data)

def getfilter(request):
    allresult = myuser.objects.filter(username__contains="sjg")
    print(allresult)
    data = serializers.serialize('json', allresult)
    return HttpResponse(data)

def delete(request):
    result = myuser.objects.filter(username='eee').delete()
    print(result)
    return HttpResponse('success')

def add(request):
    username = request.GET.get('username')
    password = request.GET.get('password')
    result = myuser.objects.create(username = username, password = password)
    print(result)
    return HttpResponse(result.username)

def update(request):
    result = myuser.objects.get(pk=184)
    result.username = 'sjg9999'
    result.save()
    print(result)
    return HttpResponse('success')